package com.team.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.team.Exception.ServiceException;
import com.team.commons.utils.ColaBeanUtils;
import com.team.commons.vo.ImageMapVo;
import com.team.entity.ImageMap;
import com.team.mapper.ImageMapMapper;
import com.team.result.StatusCode;
import com.team.service.ImageMapService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class ImageMapServiceImpl implements ImageMapService {

    @Resource
    ImageMapMapper imageMapMapper;

    @Override
    public List<ImageMapVo> selectImageMap() {
        List<ImageMapVo> imageMapVos=new ArrayList<>();
        try {
            QueryWrapper<ImageMap> eq = new QueryWrapper<ImageMap>().eq(ImageMap.COL_IMG_STATE, 1);
            List<ImageMap> imageMaps = imageMapMapper.selectList(eq);
            imageMapVos = ColaBeanUtils.copyListProperties(imageMaps, ImageMapVo::new);
        }catch (Exception e){
            throw new ServiceException(StatusCode.SERVER_ERROR);
        }
        return imageMapVos;
    }

    @Override
    public String selectImageById(Long imgId) {
        String url=null;
        try {
            QueryWrapper queryWrapper=new QueryWrapper();
            queryWrapper.select(ImageMap.COL_IMG_URL).eq(ImageMap.COL_ID,imgId);
            url = imageMapMapper.selectOne(queryWrapper).getImgUrl();
        }catch (Exception e){
            throw new ServiceException(StatusCode.SERVER_ERROR);
        }
        return url;
    }
}
